package haw.pr2.A3.implementations;

import haw.pr2.A3.interfaces.UniqueId;

/**
 *
 * @author Fabian Heidorn, Alexander Kaack
 */
public class UniqueIdImpl implements UniqueId {
    
    long id;
    private static long nextId=0;
    
    public UniqueIdImpl(long id) {
        this.id = id;
    }
    
    public static UniqueId getNextID() {
        nextId++;
        return new UniqueIdImpl(nextId);
    }
    
    
    @Override
    public long idNumber() {
        return id;
    }

    @Override
    public int compareTo(UniqueId id) {
        return (int) ((int) this.idNumber()-id.idNumber());
    }
    
    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof UniqueIdImpl)) return false;
        if (obj == this) return true;
        return (this.compareTo((UniqueIdImpl)obj) == 0);
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 37 * hash + (int) (this.id ^ (this.id >>> 32));
        return hash;
    }
   
    
}
